package com.fa4j.system.account.repository.impl;

import com.fa4j.common.data.repository.impl.BaseRepositoryImpl;
import com.fa4j.system.account.model.AccountPassword;
import com.fa4j.system.account.model.AccountPasswordType;
import com.fa4j.system.account.repository.AccountPasswordRepository;
import com.fa4j.system.account.repository.mapper.AccountPasswordMapper;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

/**
 * 账号密码 持久化接口 实现
 *
 * @since 2025-05-06 16:16:26
 */
@Repository
public class AccountPasswordRepositoryImpl extends BaseRepositoryImpl<AccountPasswordMapper, AccountPassword> implements AccountPasswordRepository {

    @Override
    public Optional<AccountPassword> findByAccountIdAndType(Long accountId, AccountPasswordType type) {
        return super.lambdaQuery()
                .eq(AccountPassword::getAccountId, accountId)
                .eq(AccountPassword::getType, type)
                .oneOpt();

    }

    @Override
    public List<AccountPassword> queryByBetweenExpireTime(LocalDateTime start, LocalDateTime end, Long minId, int size) {
        return super.lambdaQuery()
                .select(AccountPassword::getId, AccountPassword::getAccountId, AccountPassword::getType, AccountPassword::getExpireTime)
                .between(AccountPassword::getExpireTime, start, end)
                .gt(AccountPassword::getId, minId)
                .orderByAsc(AccountPassword::getId)
                .last("limit " + size)
                .list();
    }
}
